package cn.wolfcode.luowowo.mgrsite.job;

import cn.wolfcode.luowowo.article.domain.StrategyDetail;
import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.cache.service.IStrategyStatsCacheService;
import cn.wolfcode.luowowo.cache.vo.StrategyStats;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * redis --> mysql
 * 定时器:将redis中的数据保存到mysql中
 */
/*@Component
public class HotDataPersistenceJob {

    @Reference
    private IStrategyStatsCacheService strategyStatsCacheService;
    @Reference
    private IStrategyDetailService strategyDetailService;
    private int count = 0;

    @Scheduled(cron = "0/5 * * * * ?")//0秒开始,每隔5秒执行一次
    public void persistence() {
        count++;
        System.out.println("执行定时器:" + count + "次");
        //1.把数据从redis中读出来
        List<StrategyStats> list = strategyStatsCacheService.listStrategyStats();

        //2.把数据封装成detail对象
        for (StrategyStats stats : list) {
            StrategyDetail detail = new StrategyDetail();
            detail.setId(stats.getStrategyId());
            detail.setReplynum(stats.getFavornum());
            detail.setViewnum(stats.getViewnum());
            detail.setFavornum(stats.getFavornum());
            detail.setSharenum(stats.getSharenum());
            detail.setThumbsupnum(stats.getThumbsupnum());
            //3.更新到mysql
            strategyDetailService.updateStats(detail);
        }
    }
}*/
